//
//  myViewController.swift
//  股票框架
//
//  Created by 李小骥 on 2017/9/28.
//  Copyright © 2017年 李小骥. All rights reserved.
//

import UIKit
import Kingfisher


class MyViewController: UIViewController,UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate{
    //拉伸用属性
    @IBOutlet var myTableView: UITableView!
    var bgImageView: UIImageView!
    var navView: UIView!
    var stretchableView: LPStretchableHeaderView!
    var headerHeight: CGFloat = 0
    
    var myData = MyModel()
    var phoneNumberLabel = UILabel()
    var scoreLabel = UILabel()
    var levelLabel = UILabel()
    var headButton = UIButton()
    var nameLabel = UILabel()
    var headerView = UIView()
    //不能用 cellforraw 获取 cell 进行设置，因为 cell 是重用的，有时候没有重用的 cell 是 nil 值，因此登录 cell 专门来一个变量保存标签值
    var loginFlag = "登录"{
        didSet{
            myTableView.reloadData()
        }
    }
    //tableView
//    var myTableView = UITableView()
    //数据源
    var cellLabelGroups:[[CellData]]{
        get{
            let cellLabelGroup0:[CellData] = [CellData(text: "我的资料", jumpUrlString: "MyData"),CellData(text: "我的钱包", jumpUrlString: "http://xy.cctvzxjy.com/Pay/wallet"),CellData(text: "我的课程", jumpUrlString: "http://xy.cctvzxjy.com/User/my_course"),CellData(text: "学分经验", jumpUrlString: "http://xy.cctvzxjy.com/User/credit"),CellData(text: "勋章馆", jumpUrlString: "http://xy.cctvzxjy.com/User/badge")]
            let cellLabelGroup1:[CellData] = [CellData(text: "更换手机号码", jumpUrlString: "http://xy.cctvzxjy.com/User/bind_phone")]
            let cellLabelGroup2:[CellData] = [CellData(text: "充值记录", jumpUrlString: "http://xy.cctvzxjy.com/Home/Pay/record"),CellData(text: "入学测评", jumpUrlString: "http://xy.cctvzxjy.com/Home/User/questionnaire"),CellData(text: "学员体验", jumpUrlString: "http://xy.cctvzxjy.com/User/tiyan")]
            let cellLabelGroup3:[CellData] = [CellData(text: "币值使用说明", jumpUrlString: "http://xy.cctvzxjy.com/User/explain"),CellData(text: "等级制度说明", jumpUrlString: "http://xy.cctvzxjy.com/User/vip_rules"),CellData(text: "产品更新说明", jumpUrlString: "http://xy.cctvzxjy.com/Agreement/update_desc")]
            let cellLabelGroup4:[CellData] = [CellData(text: "服务须知", jumpUrlString: "http://xy.cctvzxjy.com/Agreement/serve"),CellData(text: "投诉与建议", jumpUrlString: "http://xy.cctvzxjy.com/User/complaint")]
            let cellLabelGroup5:[CellData] = [CellData(text: "登录", jumpUrlString: "loginOrlogout")]
            return [cellLabelGroup0,cellLabelGroup1,cellLabelGroup2,cellLabelGroup3,cellLabelGroup4,cellLabelGroup5]
        }
    }
    //图标源
    var cellIconGroups:[[UIImage?]] {
        get{
            //计算属性互相访问会产生循环引用，此处要避免发生循环引用
             weak var weakSelf : MyViewController? = self
            var groups:[[UIImage?]] = []
            
            for (index,cellLabelGroup) in cellLabelGroups.enumerated(){
                var cellIconGroup:[UIImage?] = []
//                此处发生了循环引用
                if(index < (weakSelf?.cellLabelGroups.count)!-1){
                    for cellLabel in cellLabelGroup{
                        let cellIcon = UIImage(named: cellLabel.text)
                        cellIconGroup.append(cellIcon)
                    }
                    groups.append(cellIconGroup)
                }
                else{
                    let emptyArray:[UIImage?] = []
                    groups.append(emptyArray)
                }
            }
            return groups
        }
    }
//    let cellIconGroup1 = [UIImage(named: "我的资料"),UIImage(named: "我的钱包"),UIImage(named: "我的课程"),UIImage(named: "我的学分")]
//    let cellIconGroup2 = [UIImage(named: "入学测评"),UIImage(named: "学员体验"),UIImage(named: "投诉与建议")]
//    let cellIconGroup3 = [UIImage(named: "会员制度说明"),UIImage(named: "服务须知"),UIImage(named: "产品更新说明")]
//    let cellIconGroup4:[UIImage?] = [UIImage(named: "服务须知")]
    
//    var cellLabelGroups11111:[[String]] {
//        get{
//            return [cellLabelGroup1,cellLabelGroup2,cellLabelGroup3,cellLabelGroup4]
//        }
//    }
//    let cellIconGroup1 = [UIImage(named: "资料"),UIImage(named: "钱包"),UIImage(named: "课程"),UIImage(named: "师徒"),UIImage(named: "会员制度")]
//    let cellIconGroup2 = [UIImage(named: "投诉建议"),UIImage(named: "体验标"),UIImage(named: "测评问卷")]
//    let cellIconGroup3 = [UIImage(named: "服务须知"),UIImage(named: "使用说明")]
//    let cellIconGroup4:[UIImage?] = [UIImage(named: "服务须知")]
//    var cellIconGroups:[[UIImage?]] {
//        get{
//            var groups:[[UIImage?]] = []
//            for (index,cellLabelGroup) in cellLabelGroups.enumerated(){
//                var cellIconGroup:[UIImage] = []
//                if(index < cellIconGroups.count-1){
//                for cellLabelString in cellLabelGroup{
//                    let cellIcon = UIImage(named: cellLabelString)!
//                    print(cellIcon)
//                    cellIconGroup.append(cellIcon)
//                }
//                groups.append(cellIconGroup)
//                }
//            }
//            return groups
//        }
    
    
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
//        for cellLabelGroup in cellLabelGroups{
//            let cellIconGroup:[UIImage] = []
//            for cellLabelString in cellLabelGroup{
//                let cellIcon = UIImage(named: cellLabelString)
//                cellIconGroup.append(cellIcon)
//            }
//            cellIconGroups.append(cellIconGroup)
//        }

//        cellIconGroups.append(cellIconGroup1 as! [UIImage])
//        cellIconGroups.append(cellIconGroup2 as! [UIImage])
//        cellIconGroups.append(cellIconGroup3 as! [UIImage])
//        cellIconGroups.append(cellIconGroup4 as! [UIImage])
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return cellLabelGroups.count
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows

            return cellLabelGroups[section].count
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let reuseIdentifier = "cell"
        var cell:MyViewCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier) as! MyViewCell
        if(cell==nil){
            cell = MyViewCell(style: .default, reuseIdentifier: reuseIdentifier)
        }
        if(indexPath.section < numberOfSections(in: myTableView) - 1){
            cell?.accessoryType = .disclosureIndicator
            cell?.textLabel?.textColor = .black
            cell?.textLabel?.textAlignment = .left
            cell?.textLabel?.text = cellLabelGroups[indexPath.section][indexPath.row].text
            cell?.imageView?.image = cellIconGroups[indexPath.section][indexPath.row]
        }else{
            cell?.accessoryType = UITableViewCellAccessoryType.none
            cell?.textLabel?.text = loginFlag
            cell?.textLabel?.textAlignment = .center
            cell?.textLabel?.textColor = .APP
            cell?.imageView?.image = nil
        }
        
        // Configure the cell...
        
        return cell!
        
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return CELL_HEIGHT
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if(myData.isLogin == true){
            jump(to:cellLabelGroups[indexPath.section][indexPath.row].jumpUrlString)
//        let nextVC = TempViewController()
//        nextVC.urlstr = cellLabelGroups[indexPath.section][indexPath.row].jumpUrlString//
//        let uuid = (lCode != nil) ? (lCode?.userID)! : "-1"
//        nextVC.para = [
//            "uuid":uuid
//        ]
//        if(nextVC.urlstr.hasPrefix("http")){
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        }else if(nextVC.urlstr == "MyData"){
//            let myDetailTableViewController = MyDetailTableViewController()
//            navigationController?.pushViewController(myDetailTableViewController, animated: true)
//        }else if(nextVC.urlstr == "logOut"){
//            if(loginFlag == "登录"){
//                jumptologin()
//            }else{
//                signOut()
//            }
//        } else{
//            //预留给其它
//        }
        }
        tableView.deselectRow(at: indexPath, animated: true)
//        switch (indexPath.section,indexPath.row) {
//        case (0,0):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/Pay/wallet"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            let myDetailTableViewController = MyDetailTableViewController()
//            navigationController?.pushViewController(myDetailTableViewController, animated: true)
//        case (0,1):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/Pay/wallet"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (0,2):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/my_course"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (0,3):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/credit"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (0,4):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/badge"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (1,0):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/badge"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (1,1):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/bind_mail"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (2,0):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/Home/Pay/record"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (2,1):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/Home/User/questionnaire"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (2,2):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/tiyan"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (3,0):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/explain"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (3,1):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/vip_rules"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (3,2):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/Agreement/update_desc"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (4,0):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/Agreement/serve"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        case (4,1):
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/complaint"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        default:
//            nextVC.urlstr = "http://xy.cctvzxjy.com/User/datum"
//            nextVC.para = [
//                "uuid":"1467"
//            ]
//            self.navigationController?.pushViewController(nextVC, animated: true)
//        }
        
//        UINavigationController(rootViewController: homeVC)
        
    }
    func jump(to:String){
        if(to.hasPrefix("http")){
//            去下一个 URL 页
            jumpToTempViewController(url:to)
        }else if(to == "MyData"){
//            去详情资料页
            jumpToMyDetailTableViewController()
        }else if(to == "loginOrlogout"){
//            做退出或者登录操作
            updateLogStatus()
        }else{
//            预留给其它
        }
    }
        func jumpToTempViewController(url:String){
            let nextVC = TempViewController()
            nextVC.urlstr = url
            nextVC.para = [
                "uuid":(lCode?.userID)!
                        ]
            let nextVCNaviController = UINavigationController(rootViewController: nextVC)
            //        self.navigationController?.pushViewController(lgvc, animated: true)
                    nextVCNaviController.navigationBar.setBackgroundColor(.APP)
    
            let viewController = UIApplication.shared.keyWindow?.rootViewController
            if let isNavigationController = viewController?.presentedViewController?.isKind(of: UINavigationController.self){
                if(isNavigationController == true){
                    let navigation = viewController?.presentedViewController as! UINavigationController
                    if(navigation.topViewController?.isKind(of: TempViewController.self))!{
                        return
                    }
                }
            }
            if((viewController?.presentedViewController) != nil){
                viewController?.presentedViewController?.dismiss(animated: false, completion: {
                    //            下方有可能改这句
                    /*viewController?.*/viewController?.present(nextVCNaviController, animated: true, completion: nil)
                    //            self.present(lgvcNaviController, animated: true, completion: nil)
                    //                viewController?.present(newWebViewNavigationController, animated: true, completion: nil)
                })
            }else{
                viewController?.present(nextVCNaviController, animated: true, completion: nil)
            }
        }
    func jumpToMyDetailTableViewController(){
        let myDetailTableViewController = MyDetailTableViewController()
        let myDetailTableViewNavigationController = UINavigationController(rootViewController: myDetailTableViewController)
        let viewController = UIApplication.shared.keyWindow?.rootViewController
        if let isNavigationController = viewController?.presentedViewController?.isKind(of: UINavigationController.self){
            if(isNavigationController == true){
                let navigation = viewController?.presentedViewController as! UINavigationController
                if(navigation.topViewController?.isKind(of: MyDetailTableViewController.self))!{
                    return
                }
            }
        }
        if((viewController?.presentedViewController) != nil){
            viewController?.presentedViewController?.dismiss(animated: false, completion: {
                //            下方有可能改这句
                /*viewController?.*/viewController?.present(myDetailTableViewNavigationController, animated: true, completion: nil)
                //            self.present(lgvcNaviController, animated: true, completion: nil)
                //                viewController?.present(newWebViewNavigationController, animated: true, completion: nil)
            })
        }else{
            viewController?.present(myDetailTableViewNavigationController, animated: true, completion: nil)
        }
    }
    func updateLogStatus(){
        if(loginFlag == "登录"){
                            jumpToLogin()
                        }else{
                            signOut()
                        }
    }
    func setupModel(){
        if let lc=lCode{
            signIn()
        }
    }

    func signIn(){
        
        //判定写在 willset islogin 改成 true
        myData.isLogin = true
        nameLabel.text = myData.user_name
        scoreLabel.text = "学分经验：\(myData.experience)"
        scoreLabel.sizeToFit()
        scoreLabel.isHidden = false
        levelLabel.text = UserLevel(rawValue: myData.user_rank)?.returnString()
        levelLabel.sizeToFit()
        levelLabel.isHidden = false
        print(myData.imageUrl)
        weak var weakSelf:MyViewController? = self
        if (myData.imageUrl != "" && myData.imageUrl != lCode?.imageUrl){
            Utils.AlamofireAsynchronousGETUserHeadImage(headHtml: myData.imageUrl){result in
                currentHeadImage = result
                weakSelf?.headButton.setBackgroundImage(currentHeadImage, alpha: 1.0, for: .normal)
            }
        }else if(currentHeadImage != nil){
                headButton.setBackgroundImage(currentHeadImage, alpha: 1.0, for: .normal)
        }
        headButton.isUserInteractionEnabled = false
        headButton.isEnabled = false
        headerView.isHidden = false
        loginFlag = "退出账号"
//        headerView.layoutSubviews()
//        headerView.layoutIfNeeded()
        
    }
    func signOut(){
        myData.isLogin = false
        nameLabel.text = "点击登录"
        scoreLabel.text = ""
        scoreLabel.isHidden = true
        levelLabel.text = ""
        levelLabel.isHidden = true
        headButton.setBackgroundImage(UIImage(named:"unloginHead.png"), for: .normal)
        headButton.isUserInteractionEnabled = true
        headButton.isEnabled = true
        loginFlag = "登录"
        
    }
    func setupHeadViews(){
                //         头视图背景图片
        headerView.frame = bgImageView.bounds
        //        headerView.height -= 80 // 对背景图片进行一部分的遮盖（可选，，可以不遮盖。。。）
        headerHeight = headerView.height
        myTableView.tableHeaderView = headerView
        //        手机号码的 label
        
//        phoneNumberLabel = UILabel(x: PHONENUMBERLABEL_X, y: PHONENUMBERLABEL_Y, height: PHONENUMBERLABEL_HEIGHT, text: myData.phoneNumber, font: PHONENUMBERLABEL_FONT, aliment: .center, color: .white)
        //        headerView.addSubview(phoneNumberLabel)
        //        学分的 label
        scoreLabel = UILabel(x: SCORELABEL_X, y: SCORELABEL_Y, height: SCORELABEL_HEIGHT, text: "123", font: SCORELABEL_FONT, aliment: .center, color: .white)
        headerView.addSubview(scoreLabel)
        //        等级的 label
        levelLabel = UILabel(x: LEVELLABEL_X, y: LEVELLABEL_Y, height: LEVELLABEL_HEIGHT, text: "", font: LEVELLABEL_FONT, aliment: .center, textColor: .white, backgroundColor: .LevelLabelBackground)
        headerView.addSubview(levelLabel)
        nameLabel = UILabel(x: PHONENUMBERLABEL_X, y: PHONENUMBERLABEL_Y, height: PHONENUMBERLABEL_HEIGHT, text: "点击登录", font: PHONENUMBERLABEL_FONT, aliment: .center, color: .white)
        headerView.addSubview(nameLabel)
        headerView.isHidden = false
        //        圆形头像按钮
        //        头视图的半径
        //        x 起点是头视图宽的一半减去半径（保证居中），y 起点是头视图高的一半减去直径
        headButton = UIButton(frame: CGRect(x: HEADBUTTON_X, y: HEADBUTTON_Y, width: HEADBUTTONDIAMETER, height: HEADBUTTONDIAMETER))
        //直接设置按钮的背景颜色才有效，不要设置按钮的 imageview（无效）

        
        //        设置圆角：1.layer的半径cornerRadius是宽度一半；2.layer 的覆盖masksToBounds为 true
        headButton.layer.cornerRadius = HEADBUTTONDIAMETER/2
        headButton.layer.masksToBounds = true
        headButton .addTarget(self, action: #selector(jumpToLogin), for: .touchUpInside)
        headerView.addSubview(headButton)
        if(myData.isLogin == false){
        nameLabel.text = "点击登录"
        scoreLabel.isHidden = true
        levelLabel.isHidden = true
        headButton.setBackgroundImage(UIImage(named:"unloginHead.png"), for: .normal)
        headerView.isUserInteractionEnabled = true
        headButton.isUserInteractionEnabled = true
        headButton.isEnabled = true
        myTableView.cellForRow(at: IndexPath(row: 1, section: cellLabelGroups.endIndex-1))?.textLabel?.text = "登录"
        }else{
            nameLabel.text = myData.user_name
            scoreLabel.isHidden = false
            levelLabel.isHidden = false
            if(currentHeadImage == nil){
            headButton.setBackgroundImage(UIImage(named:"unloginHead.png"), for: .normal)
            }else{
                headButton.setBackgroundImage(currentHeadImage, for: .normal)
            }
            headerView.isUserInteractionEnabled = true
            headButton.isUserInteractionEnabled = false
            headButton.isEnabled = false
            myTableView.cellForRow(at: IndexPath(row: 1, section: cellLabelGroups.endIndex-1))?.textLabel?.text = "退出账号"
        }
    }
    @objc func jumpToLogin(){
        let lgvc = LoginViewController()
        lgvc.myViewDelegate = self
        lgvc.jumpFrom = .my
        lgvc.title = "登录"
        let lgvcNaviController = UINavigationController(rootViewController: lgvc)
//        self.navigationController?.pushViewController(lgvc, animated: true)
//        lgvcNaviController.navigationBar.setBackgroundColor(.APP)
        lgvcNaviController.navigationBar.titleTextAttributes = (naviBarTitleAttributes as! [NSAttributedStringKey : Any])
        let viewController = UIApplication.shared.keyWindow?.rootViewController
        if let isNavigationController = viewController?.presentedViewController?.isKind(of: UINavigationController.self){
            if(isNavigationController == true){
                let navigation = viewController?.presentedViewController as! UINavigationController
                if(navigation.topViewController?.isKind(of: DKSWebViewController.self))!{
                    return
                }
            }
        }
        if((viewController?.presentedViewController) != nil){
                        viewController?.presentedViewController?.dismiss(animated: false, completion: {
//            下方有可能改这句
                            /*viewController?.*/viewController?.present(lgvcNaviController, animated: true, completion: nil)
//            self.present(lgvcNaviController, animated: true, completion: nil)
            //                viewController?.present(newWebViewNavigationController, animated: true, completion: nil)
                        })
        }else{
            viewController?.present(lgvcNaviController, animated: true, completion: nil)
        }
    }
    func setupBGImageView(){
        //        拉伸视图相关代码
        bgImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: HEADVIEW_HEIGHT))
        bgImageView.image = UIImage(named: "headBackground.jpg")
        view.addSubview(bgImageView)
    }
    func setupMyTableView(){
        myTableView = UITableView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
        myTableView.register(MyViewCell.self, forCellReuseIdentifier: "cell")
        myTableView.dataSource = self
        myTableView.delegate = self
        myTableView.showsVerticalScrollIndicator = false
        myTableView.backgroundColor = .clear
        view.addSubview(myTableView)
    }
    func makeStretchableView(){
        stretchableView = LPStretchableHeaderView(stretchableView: bgImageView)
    }
    func setBackgroundColor(){
        self.view.backgroundColor = .Background
    }
    func setSectionHeight(){
        myTableView.sectionFooterHeight = 0
        myTableView.sectionHeaderHeight = 0
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupBGImageView()
        setupMyTableView()
        makeNavView()
        makeStretchableView()
        setBackgroundColor()
        setSectionHeight()
        setupHeadViews()
        setupModel()
        //颜色设置相关代码
        
        //        self.navigationController?.navigationBar.barTintColor = .red
        //        myTableView = UITableView(frame: UIScreen.main.bounds)
        //        myTableView.delegate = self
        //        myTableView.dataSource = self
        //        self.view.addSubview(myTableView)
        //        myTableView.register(myViewCell.self, forCellReuseIdentifier: "cell")
        
        //        暂时测试用1.png 来调整头视图位置，过后只需修改图片即可
        //        let headerView = UIView(frame:
        //            CGRect(x:0, y:0, width:myTableView.frame.size.width, height:120))
        //        let headerImage = UIImageView(frame: headerView.bounds)
        //        headerImage.image = UIImage(named: "1.png")
        //        headerView.addSubview(headerImage)
        //        myTableView.tableHeaderView = headerView
        //
        //        UIApplication.shared.isStatusBarHidden = true
//        UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
        
        // Do any additional setup after loading the view.
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        UIApplication.shared.statusBarStyle = .lightContent
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    // 导航栏
    func makeNavView() {
        
        navView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 64))
        view.addSubview(navView)
        
        let titleLabel = UILabel(frame: navView.bounds)
        titleLabel.text = "导航栏标题"
        titleLabel.textColor = UIColor.white
        titleLabel.textAlignment = .center
        navView.addSubview(titleLabel)
    }
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        // 导航栏设置
        let yOffset = scrollView.contentOffset.y
        if yOffset < (headerHeight - navView.height) {
            let alpha = yOffset / (headerHeight - navView.height)
            navView.backgroundColor = UIColor.RGB_COLOR(74, g: 163, b: 243, alpha: alpha)
        } else {
            navView.backgroundColor = UIColor.RGB_COLOR(74, g: 163, b: 243, alpha: 1)
        }
        
        stretchableView.scrollViewDidScroll(scrollView)
    }
    
    
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */
    
}

